The present invention relates to compiling an application in a computer system, and more specifically, to a method for a compiling optimization of an application.
Nowadays, an application needs to be capable of handling information coming from outside of the application as external information. The external information may include, but is not limited to, execution environment variables (e.g., variables representing operation system level, etc.), command-line input from a user, an external configuration file of the application, etc.
Usually, a developer of an application uses branch selection statements such as an IF/ELSE or SWITCH statement in source code to implement processing of the external information.
However, in some cases, the application may be required to always run on a stable environment or only be applied to one specific scenario. Thus, when the application is running, branch selection statements of related variables actually only run one branch statement, while other branch statement(s) become redundant. These redundant branch statements are still included in the application's executable file, thereby increasing the size of the executable file and slowing the overall performance of the application.
In order to avoid the above situations, a conventional method is to preprocess the source code of the application using a preprocessing command such as # ifdef prior to compiling the source code. The preprocessing command may help delete unwanted branches when compiling.
Such preprocessing is suitable for well-architected applications, but not suitable for non-well-architected applications including a large amount of legacy code. In addition, this preprocessing may lead to larger code, that is hard to read, and cannot adapt to all the scenarios flexibly.